package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 简报推送类型
 * @author zcp
 * @version v1.0
 * @date 2019/4/16 11:02
 * @since v1.0
 */
@Getter
public enum ReportTypeEnum {

    /**
     * 推送昨日数据
     */
    DAY(1, "enum.reportType.name.day"),
    /**
     * 推送上周数据
     */
    WEEK(2, "enum.reportType.name.week"),
    /**
     * 推送上月数据
     */
    MONTH(3, "enum.reportType.name.month"),

    UNKNOWN(404, "enum.reportType.name.unknown"),
    ;

    /**
     * 报告类型code值
     */
    private int code;
    /**
     * 图表类型名
     */
    private String name;

    ReportTypeEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 根据code值获取枚举
     * @param code
     * @return
     */
    public static ReportTypeEnum getByCode(Integer code) {
        for (ReportTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.code,code)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
